﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Net;
using System.Net.NetworkInformation;

namespace NetMonitor.Server
{
    public class NetLine
    {
        public NetLine(NetNode n1, NetNode n2, Color c)
        {
            node1 = n1;
            node2 = n2;
            lineColor = c;
        }

        #region 属性

        private string id;        
        public string ID
        {
            get { return id; }
            set { id = value; }
        }

        private Color lineColor;
        public Color LineColor
        {
            get { return lineColor; }
            set { lineColor = value; }
        }

        private NetNode node1;
        public NetNode Node1
        {
            get { return node1; }
            set { node1 = value; }
        }

        private NetNode node2;
        public NetNode Node2
        {
            get { return node2; }
            set { node2 = value; }
        }


        #endregion
        

        #region 方法

        // lryh 连通状态标志
        private string connectivity = CONNECTIVITY_ALARM;
        public string Connectivity
        {
            get 
            {   return connectivity; }
            // set { connectivity = value; }
        }

        private void changeState(string value)
        {
            connectivity = value;
            if (value == CONNECTIVITY_ALARM)
                logToDb(false);
            else if (value == CONNECTIVITY_NORMAL)
                logToDb(true);
        }

        private string insertSql = "insert into NodeEvent (pointid, ipaddress, status, logtime) "
                                 + "values (@p0, @p1, @p2, GetDate())";

        private void logToDb(bool up)
        {
            try
            {
                using (DataClasses1DataContext dc = new DataClasses1DataContext())
                {
                    
                }
            }
            catch (Exception e)
            {
                System.Console.Out.WriteLine(e.Message);
                System.Console.Out.WriteLine(e.StackTrace);
            }
        }

       
        // lryh 连通状态
        public const string CONNECTIVITY_NORMAL = "normal";
        public const string CONNECTIVITY_WARNING = "warning";
        public const string CONNECTIVITY_ALARM = "alarm";

        
        /// <summary>
        /// 开始ping
        /// </summary>
        public void StartPing()
        {            
                
        }

        private Ping pingClient;

        /// <summary>
        /// 停止ping
        /// </summary>
        public void StopPing()
        {
            
        }

        
        #endregion

    }
}
